<template>
  <div class="userinfo">
     <van-cell title="用户信息更改" is-link to="/reviseinfo"/>
     <van-cell title="账号密码重置" is-link  to="/resetinfo"/>
     <van-button type="warning" color="#ff6a6c" round @click="onlogout">退出登录</van-button>
  </div>
</template>

<script>
import { Cell, CellGroup,Button,Toast } from 'vant';
import API from "@/utils/api.js";
export default {
  name:"UserInfo",
  data(){
      return{

      }
  },
  methods:{
    onlogout(){
     this.$post(API.POST_AUTH_LOGOUT, {
          token: this.$store.state.token,
        })
          .then((res) => {
            console.log(res);
            Toast.success("退出成功");
            //调用后台退出登录接口清token
            localStorage.removeItem("token");
            localStorage.removeItem("userInfo");
            this.$store.dispatch("logout");
            this.$router.push("/home");
          })
          .catch((err) => {
            console.log(err);
          });
    }
  },
   components: {
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Button.name]: Button
  },
}
</script>

<style lang="less" scoped>
.userinfo{
  margin-top: 46px;
  .van-button {
    width: 300px;
    height: 40px;
    margin-left: 30px;
    margin-top: 120px;
  }
}
</style>